/*
 * ﻿Copyright (C) 2011-2013 NewMain Softech
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package com.newmainsoftech.aspectjutil.eventmanager.testmodels;

import java.util.List;

import com.newmainsoftech.aspectjutil.eventmanager.EventInfo;
import com.newmainsoftech.aspectjutil.eventmanager.label.EventListener;
import com.newmainsoftech.aspectjutil.eventmanager.label.OnEvent;
import com.newmainsoftech.aspectjutil.eventmanager.label.PreEvent;

/**
 * Test helper class being used by test event listener model class found in same package in order to  
 * record the incidence of execution of event listener method annotated with either {@link PreEvent} 
 * or {@link OnEvent}. 
 * From this class, any reference to test event listener model class annotated with {@link EventListener} 
 * should not be made. The reason is to avoid triggering loading of such test model class automatically 
 * when this class is loaded. 
 */
public class EventTraceSupporter {
	/**
	 * All test event listener model class annotated with {@link EventListener} will record the execution 
	 * incidence of event listener method annotated with either {@link PreEvent} or {@link OnEvent}. 
	 * Thereby, test classes refer to any of those test vent listener model classes should initialize 
	 * this eventTraceList (before each test method execution.)
	 */
	protected static List<String> eventTraceList = null;
	synchronized public static void setEventTraceList( List<String> eventTraceList) {
		EventTraceSupporter.eventTraceList = eventTraceList;
	}
	public static final List<String> getEventTraceList() {
		return eventTraceList;
	}
	public static final void clearEventTraceList() {
		eventTraceList.clear();
	}
	
	protected static List<Object> eventerTraceList = null;
	public static final List<Object> getEventerTraceList() {
		return eventerTraceList;
	}
	synchronized public static final void setEventerTraceList( List<Object> eventerTraceList) {
		EventTraceSupporter.eventerTraceList = eventerTraceList;
	}

	protected static List<Object> eventResultTraceList = null;
	public static final List<Object> getEventResultTraceList() {
		return eventResultTraceList;
	}
	synchronized public static final void setEventResultTraceList( List<Object> eventResultTraceList) {
		EventTraceSupporter.eventResultTraceList = eventResultTraceList;
	}
	
	protected static List<Class<?>> triggeredEventTraceList = null;
	public static final List<Class<?>> getTriggeredEventTraceList() {
		return triggeredEventTraceList;
	}
	synchronized public static final void setTriggeredEventTraceList( List<Class<?>> triggeredEventTraceList) {
		EventTraceSupporter.triggeredEventTraceList = triggeredEventTraceList;
	}
	
	synchronized public static void saveEventInfo( EventInfo eventInfo) {
		EventTraceSupporter.getTriggeredEventTraceList().add( eventInfo.getTriggeredEvent());
		EventTraceSupporter.getEventResultTraceList().add( eventInfo.getResult());
		EventTraceSupporter.getEventerTraceList().add( eventInfo.getEventerInfo());
	}
}
